﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace FeedAntGame.Sprite
{
    sealed class Cursor : BaseSprite
    {
        public enum STATE_TYPE { NORMAL, C, HAND, NORMAL_AND_C }
        private STATE_TYPE _state = STATE_TYPE.NORMAL;
        private ContentManager content;
        /************************************************************************/
        /*                      Get/Set                                                                     */
        /************************************************************************/
        
        public STATE_TYPE State 
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
                switch (_state)
                {
                    case STATE_TYPE.NORMAL:
                        textureImage = content.Load<Texture2D>(@"Images\cursor_normal");
                        break;
                    case STATE_TYPE.C:
                        textureImage = content.Load<Texture2D>(@"Images\cursor_c");
                        break;
                    case STATE_TYPE.HAND:
                        textureImage = content.Load<Texture2D>(@"Images\cursor_hand");
                        break;
                    case STATE_TYPE.NORMAL_AND_C:
                        textureImage = content.Load<Texture2D>(@"Images\cursor_pointer_c");
                        break;
                }
            }
        }


        MouseState prevMouseState;

        /************************************************************************/
        /*                      Constructors                                                */
        /************************************************************************/
        public Cursor(Texture2D textureImage, Vector2 position,
            Point frameSize, int collisionOffset, Point currentFrame, Point sheetSize, ContentManager content)
            : base(textureImage, position, frameSize, collisionOffset, currentFrame,
            sheetSize, Vector2.Zero, null, 0, 1)
        {
            this.content = content;
        }

        
        public override Vector2 Direction
        {
            get
            {
                return speed;
            }
        }

        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {

            // Move the sprite based on Direction
            Position += Direction;
            // If player moved the mouse, move the sprite
            MouseState currMouseState = Mouse.GetState();
            if (currMouseState.X != prevMouseState.X ||
                currMouseState.Y != prevMouseState.Y)
            {
                
                switch (State)
                {
                    case STATE_TYPE.HAND:
                        Position = new Vector2(currMouseState.X - 10, currMouseState.Y);
                        break;

                    default:
                        Position = new Vector2(currMouseState.X, currMouseState.Y);
                        break;
                } 
                 
                    
            }
            prevMouseState = currMouseState;
            // If sprite is off the screen, move it back within the game window
            if (Position.X < 0)
                position.X = 0;
            if (Position.Y < 0)
                position.Y = 0;
            if (Position.X > clientBounds.Width - frameSize.X)
                position.X = clientBounds.Width - frameSize.X;
            if (Position.Y > clientBounds.Height - frameSize.Y)
                position.Y = clientBounds.Height - frameSize.Y;
            base.Update(gameTime, clientBounds);

        }

        public Vector2 GetPosition()
        {
            return Position;
        }
    }
}
